cmake_minimum_required(VERSION 3.20)
project(KitharaDeviceTest)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 定义系统类型
if(WIN32)
    # 添加定义
    set(OS_TYPE "Windows")
else()
    set(OS_TYPE "Linux")
endif()

# 定义构建类型
if(CMAKE_BUILD_TYPE MATCHES "Debug")
    set(BUILD_TYPE "Debug")
    add_definitions(
            -DWIN32
            -D_DEBUG
            -D_CONSOLE
            -D_WINDOWS
            -D_USRDLL
            -D_WINDLL
    )
else()
    set(BUILD_TYPE "Release")

    # Release 设置代码运行优化
    set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -O2")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
endif()

# 设置库输出路径
set(BUILD_BIN_DIR "${CMAKE_SOURCE_DIR}/Bin/${OS_TYPE}${BUILD_TYPE}")
set(BUILD_LIB_DIR "${CMAKE_SOURCE_DIR}/Lib/${OS_TYPE}${BUILD_TYPE}")

# 设置Kithara库路径
set(KITHARA_INCLUDE_PATH "C:/Program Files/Kithara/LinkControl RealTime Driver/dev")
set(KITHARA_LIB_PATH "C:/Program Files/Kithara/LinkControl RealTime Driver/dev")

# 静态库保存位置
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR})
# 动态库保存位置
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR})

# 设置编码格式为utf-8
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

# 引入本项目的头文件 Lib库
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
link_directories("${BUILD_LIB_DIR}")

# 查找Qt库
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Quick)
# 未设置环境变量可手动指定Qt路径，重新加载需删除IDE缓存
#set(CMAKE_PREFIX_PATH "E:/Qt/5.15.2/msvc2019_64/lib/cmake")

# Kithara头文件 Lib库
include_directories("${KITHARA_INCLUDE_PATH}")
link_directories("${KITHARA_LIB_PATH}")

# 设置输出路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR}/${PROJECT_NAME})

# 程序集
add_subdirectory(Kernel)
add_subdirectory(KitharaTest)
add_dependencies(KitharaTest Kernel)

# 平台信息
message("SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message("SYSTEM_NAME: ${OS_TYPE}")
message("BUILD_TYPE: ${BUILD_TYPE}")
message("OUTPUT:" ${BUILD_BIN_DIR})
message("QT_VERSION:" ${QT_VERSION_MAJOR})
